package cn.com.gas.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.gas.mapper.GasJyzxxImportCygxxMapper;
import cn.com.gas.entity.GasJyzxxImportCygxxEntity;
import cn.com.gas.service.GasJyzxxImportCygxxService;
import cn.com.thirdparty.entity.JyzxxImportCygxxEntity;
import cn.com.thirdparty.service.JyzxxImportCygxxService;
import cn.com.util.TsBqUtils;


@Service("gasJyzxxImportCygxxService")
public class GasJyzxxImportCygxxServiceImpl extends ServiceImpl<GasJyzxxImportCygxxMapper, GasJyzxxImportCygxxEntity> implements GasJyzxxImportCygxxService {
	
	@Autowired
	private JyzxxImportCygxxService jyzxxImportCygxxService;
	
	@Override
	public void saveCygxx(GasJyzxxImportCygxxEntity gasJyzxxImportCygxx) {
		try {
			Date date = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String strDate = sdf.format(date);
			
			gasJyzxxImportCygxx.setId(TsBqUtils.getUUID());
			gasJyzxxImportCygxx.setUpdateTime(strDate);
			
			this.save(gasJyzxxImportCygxx);
			
			JyzxxImportCygxxEntity entity = new JyzxxImportCygxxEntity();
			BeanUtils.copyProperties(gasJyzxxImportCygxx, entity);
			
			// 写入 第三方数据库
			jyzxxImportCygxxService.saveCygxx(entity);
			
		} catch (Exception e) {
			log.error("jyzxxImportCygxxService.saveCygxx异常:"+e.getMessage());
		}
	}

	@Override
	public void removeByIdsCygxx(List<String> ids) {
		try {
			
			for (String id : ids) {
				this.removeById(id);
				// 写入 第三方数据库
				jyzxxImportCygxxService.removeByIdCygxx(id);
				
			}
		} catch (Exception e) {
			log.error("jyzxxImportCygxxService.removeByIdsCygxx异常:"+e.getMessage());

		}
	}

	@Override
	public void updateByIdCygxx(GasJyzxxImportCygxxEntity gasJyzxxImportCygxx) {
		try {
			
			Date date = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String strDate = sdf.format(date);
			
			gasJyzxxImportCygxx.setUpdateTime(strDate);
			
			this.updateById(gasJyzxxImportCygxx);
			
			JyzxxImportCygxxEntity entity = new JyzxxImportCygxxEntity();
			BeanUtils.copyProperties(gasJyzxxImportCygxx, entity);
			
			// 写入 第三方数据库
			jyzxxImportCygxxService.updateByIdCygxx(entity);
			
		} catch (Exception e) {
			log.error("jyzxxImportCygxxService.updateByIdCygxx异常:"+e.getMessage());

		}
	}


}